package com.freshcity.page.talk
{
	import com.freshcity.component.container.Component;
	import com.freshcity.core.MainScene;
	import com.freshcity.core.OpCodes;
	import com.freshcity.manager.LayerManager;
	import com.freshcity.talk.ReplyTalkWin;
	import com.freshcity.utils.BitmapUtil;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	public class ReplyTalk extends Component
	{
		private var data:*;
		private var back:ReplyTalkWin;
		
		public function ReplyTalk(main:MainScene,data:*)
		{
			this.main = main;
			this.data = data;
			super(LayerManager.popupLayer, 0, 0);
			
			back.rejectBtn.addEventListener(MouseEvent.CLICK,onReject);
			back.acceptBtn.addEventListener(MouseEvent.CLICK,onAccept);
			back.closeBtn.addEventListener(MouseEvent.CLICK,onHide);
		}
		
		protected function onAccept(event:MouseEvent):void
		{
			main.commu.send(OpCodes.START_TALK, {u: data.user.id,f:int(data.user.sendFlowers)});
			onHide();
		}
		
		protected function onReject(event:MouseEvent):void
		{
			main.msg.showFixRollMsg("拒绝了用户"+ data.user.id +"的聊天请求。");
			main.commu.send(OpCodes.REJECT_TALK, {u: data.user.id});
			onHide();
		}
		
		override protected function addChildren():void
		{
			super.addChildren();
			back = new ReplyTalkWin();
			addChild(back);
		}
		
		override public function draw():void
		{
			super.draw();
			
			this.x = (main.stage.stageWidth-380)/2;
			this.y = (main.stage.stageHeight-345)/2;
			resort();
		}
		
		private function resort():void
		{
			back.sendName.text=data.user.id;
			back.assoValue.toolTipData="友好度";
			back.assoValue.setValue(data.user.sendAssoValue);
			back.userPic.gotoAndStop(data.user.sex);
			BitmapUtil.showAvatarPic(data.user, back.userPic);
			back.income.text=String(data.user.income);
			back.words.text=data.user.friendDesc;
			back.flowAmt.text=String(data.user.sendFlowers);
			
			var up:UserDetailPanel = new UserDetailPanel(data.user, data.report);
			up.main = main;
			back.infoPanel.source = up;
		}		
		
		private function onHide(event:Event=null):void
		{
			back.rejectBtn.removeEventListener(MouseEvent.CLICK,onReject);
			back.acceptBtn.removeEventListener(MouseEvent.CLICK,onAccept);
			if(this.parent)this.parent.removeChild(this);
		}
		
	}
}